diff options
| author | trisusilo <tri.susilo@altama.co.id> | 2024-10-25 07:46:05 +0000 |
|---|---|---|
| committer | trisusilo <tri.susilo@altama.co.id> | 2024-10-25 07:46:05 +0000 |
| commit | 9bece5cc8b9c800b76dcd65b9c5e2aed60d24278 (patch) | |
| tree | 44982ef93420088f49933c06a2d469e9ce91b992 /src/pages/shop/find/[slug].jsx | |
| parent | e0aa9e04a473a4f7a21b389b42314d3fed06b43e (diff) | |
| parent | 16e46197ee2c9879ae8ef9a68d4ce67ae68843e3 (diff) | |
Merged in feature/page_category_brand (pull request #356)
Feature/page category brand
Diffstat (limited to 'src/pages/shop/find/[slug].jsx')
| -rw-r--r-- | src/pages/shop/find/[slug].jsx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/pages/shop/find/[slug].jsx b/src/pages/shop/find/[slug].jsx new file mode 100644 index 00000000..e7b8bd48 --- /dev/null +++ b/src/pages/shop/find/[slug].jsx @@ -0,0 +1,66 @@ +import axios from 'axios'; +import { useRouter } from 'next/router'; +import { useEffect, useState } from 'react'; +import Seo from '@/core/components/Seo'; +import dynamic from 'next/dynamic'; +import { get } from 'lodash-contrib'; +import { getIdFromSlug, getNameFromSlug } from '@/core/utils/slug'; + +const BasicLayout = dynamic(() => + import('@/core/components/layouts/BasicLayout') +); +const ProductSearch = dynamic(() => + import('@/lib/product/components/ProductSearch') +); + +const BASE_URL = 'https://indoteknik.com'; +export default function FindPage() { + const route = useRouter(); + const qSlug = route?.query?.slug || null; + const url = BASE_URL + route.asPath; + const [result, setResult] = useState(null); + const [query, setQuery] = useState(null); + + const slug = qSlug ? getNameFromSlug(route?.query?.slug) +' '+ getIdFromSlug(route?.query?.slug) : ''; + const getUrls = async (url) => { + try { + let response = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/url-category_brand?url=${url}` + ); + let result = response?.data?.response?.docs[0] || null; + setResult(result); + } catch (error) { + console.error('Error fetching data:', error); + } + }; + + useEffect(() => { + getUrls(url); + }, []); + + useEffect(() => { + if (result) { + let fq = `category_parent_ids:${result.category_id_i} AND manufacture_id_i:${result.brand_id_i}`; + setQuery({ + fq: fq, + }); + } + }, [result]); + + return ( + <BasicLayout> + <Seo + title={`Jual ${slug} original - indoteknik.com`} + description={`Jual ${slug} Kirim Jakarta Surabaya Semarang Makassar Manado Denpasar Balikpapan Medan Palembang Lampung Bali Bandung Makassar Manado.`} + additionalMetaTags={[ + { + property: 'keywords', + content: `Jual ${slug}, harga ${slug}, ${slug} murah, toko ${slug}, ${slug} jakarta, ${slug} surabaya`, + + }, + ]} + /> + {query && <ProductSearch query={query} prefixUrl={`${route.asPath}`} />} + </BasicLayout> + ); +} |
